<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link rel="stylesheet" href="../../css/reset.css" />
		<link href="../../js/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet">
		<link rel="stylesheet" type="text/css" href="footer.css" />
		<link rel="stylesheet" href="../../css/lystyle.css" />
		<link rel="stylesheet" href="../../css/backstage.css" />
		<style type="text/css">
			/*修改底部字体颜色*/
			
			.foot:nth-child(2) {
				color: #e83023;
			}
			
			.vip_msg_add {
				width: 100%;
				margin: 0 auto;
				margin-bottom: 0.75rem;
				margin-top: 0.75rem;
			}
			
			input,
			button {
				border: 0;
				outline: none;
			}
		</style>
		<script src="../../js/flexible.min.js" type="text/javascript" charset="utf-8"></script>
	</head>

	<body class="ly-bgcolor">
		<div id="wrap">
			<div id="main">
				<div id="header">
					<a id="headImg" href="javascript:history.go(-1)"><img class="headImg" src="../../images/12.png" /></a>
					<p id="headTitle">密码修改</p>
				</div>
				<div id="content" style="padding-bottom: 1.319444rem;">
					<div class="ly-form">
						<div class="vip_msg_add" style="overflow: hidden;margin-bottom: 15px;"> <span class=" col-xs-3" style="padding-top: .22rem;text-align: right;font-weight: 600;color: #5E5F60;">动态码:</span>
							<div class="col-xs-8">
								<input class="form-control" style="border: 1px solid #ccc;padding: 6px;border-radius:0.1rem ;width: 3.3rem;position:relative;left:-.23rem;display: inline-block;" type="text" name="" id="dongTai" value="" placeholder="请输入动态码"><button style="background: red;color: white;border: 0;float: right;margin-right: .2rem;margin-top: 4px;padding: 2px;border-radius: 0.2125rem;" id="getBtn">免费获取</button>
							</div>
						</div>
						<div class="form-group row">
							<label class="control-label col-xs-3 ly-form-label" style="text-align: right;">填写新密码</label>
							<div class="col-xs-8"><input class="form-control" type="password" id="pwd" /></div>
						</div>
						<div class="form-group row">
							<label class="control-label col-xs-3 ly-form-label" style="text-align: right;">确定密码</label>
							<div class="col-xs-8"><input class="form-control" / type="password" id="repwd"></div>
						</div>
						<div class="row">
							<a style="color: #fff;" class="ly-borderp col-xs-3" id="sure">确定</a>
							<a style="color: #fff;" class="ly-borderp col-xs-3" id="cancle">取消</a>
						</div>
					</div>
				</div>
			</div>
		</div>

	</body>
	<script src="../../js/jquery-2.2.3.min.js"></script>
	<script src="../../../common/js/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
	<script src="../../js/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
	<script type="text/javascript">
		var tokenReztApp = $.cookie("tokenReztApp");
		if(!tokenReztApp) {
			window.location.href = "../login/login/login.html";
		}
		$(function() {
			currentyf();
		});

		//用户信息
		var user, role, goodsId;
		//获取当前会员信息
		function currentyf() {
			$.ajax({
				cache: false,
				type: "GET",
				url: "http://47.104.13.109/member-service/auth/current?token=" + tokenReztApp,
				dataType: "JSON",
				async: false,
				error: function(XMLHttpRequest, textStatus, errorThrown) {
					$.removeCookie('tokenReztApp', {
						expires: 7,
						path: '/'
					});
					$.removeCookie("tokenRh", {
						expires: 7,
						path: '/'
					});
					$.removeCookie('memberId', {
						expires: 7,
						path: '/'
					});
					$.removeCookie('roleId', {
						expires: 7,
						path: '/'
					});
					window.location.href = "../login/login/login.html";
				},
				success: function(data) {
					user = data.loginName;
					role = data.roleList[0].id; //角色
					goodsId = data.id;

				}
			});
		}
		var local = 'http://47.104.13.109/member-service';
		$(function() {
			$("#cancle").on("click", function() {
				history.go(-1);
			})

			//获取验证码 手机号从哪来
			$("#getBtn").on("click", function() {
					$.ajax({
						type: "get",
						url: "http://47.104.13.109/member-service/member/mine/member?token=" + $.cookie('tokenRh'),
						async: true,
						success: function(res3) {

							console.log(res3)
							var phone = res3.tel;
							$.ajax({
								type: "get",
								url: local + '/register/send-sms-code',
								async: true,
								data: {
									'tel': phone,
								},
								success: function(res) {
									console.log(res);
									$("#getBtn").prop("disabled", 'disabled');
									$("#getBtn").text("请稍等");
									$("#getBtn").css("background", "gray");
								},
								error: function(error) {
									console.log(error);
									var s = JSON.parse(error.responseText);
									alert(s.error_message);
								}
							});

						}
					});
				})
				//				//验证密码
				//				$("#repwd").on("blur",function(){
				//					var pwd = $("#pwd").val(),
				//						repwd = $("#repwd").val();
				//					console.log(pwd+repwd);
				//					if (repwd!=pwd) {
				//						alert("两次密码不一致!");
				//						$("#repwd").val("");
				//					} 
				//				})
			$("#sure").on('click', function() {
				//密码一致
				var pwd = $("#pwd").val(),
					repwd = $("#repwd").val(),
					dongtai = $("#dongTai").val();

				$.ajax({
					type: "get",
					url: "http://47.104.13.109/member-service/auth/current?token=" + $.cookie("tokenRh"),
					async: true,
					success: function(res1) {
						var phone = res1.tel;

						if(pwd) {
							//验证验证码
							$.ajax({
								type: "post",
								url: local + '/auth/security/validate',
								async: true,
								data: {
									'mobile': phone,
									'mobileCode': '123', //动态验证码
									'key': 'bingding' //绑定关键字

								},
								success: function(res) {
									console.log(res);
									//修改密码
									$.ajax({
										type: "post",
										url: local + "/auth/security/password",
										async: true,
										data: {
											'pwd': pwd,
											'repwd': repwd,
											'authcode': 'wqeeww'
										},
										success: function(res) {
											console.log(res);
											//暂时alert
											alert("修改成功");
											history.go(-1);
										},
										error: function(error) {
											console.log(error);
											//var s = JSON.parse(error.responseText);
											//alert(s.message);
										}

									});

								},
								error: function(error) {
									console.log(error);
									//								var s = JSON.parse(error.responseText);
									alert(error.responseJSON.message);
								}
							});

						}
					}
				});

			})

		})
	</script>

</html>